/<template>
  <div class="login">
    <!-- <h1>login</h1> -->
    <!-- <p>
      <span>账号</span>
      <input type="text" />
    </p>
    <p>
      <span>密码</span>
      <input type="text" />
    </p>
    <button @click="submit">登录</button> -->
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
// import request from "../../utils/request";
// import "../../api/login";
import { mapState, mapActions } from "vuex";
export default {
  name: "LoginIndex",
  // methods: {
  //   submit() {
  //     request.get("/logins").then((res) => {
  //       window.localStorage.setItem("token", res.data.token);
  //       console.log(res.data.message);
  //       this.$router.push("/home");
  //     });
  //   },
  // },
  data() {
    return {
      username: "admin",
      password: "123456",
    };
  },
  computed: {
    ...mapState("login", ["user"]),
  },
  methods: {
    ...mapActions("login", ["asyncLogin"]),
    async onSubmit(values) {
      // console.log("submit", values);
      await this["asyncLogin"](values);
      if (this.user.nickname) {
        this.$toast.success("登录成功");
        this.$router.back();
      }
    },
  },
};
</script>

<style scoped lang="scss">
</style>